// pages/activity_video/activity_video.js
import { Activityvideo } from '../../model/activity_video.js'
const activityvideo = new Activityvideo();
var WxParse = require('../../wxParse/wxParse.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        isvideo:false,
        id:'',
        content:'',
        detailobj:{},
        categoryMenu: ["简介", "视频"],
        categoryCur:0,
        detailsList:[],
        activityVideoId:'',
        VideoIdactivity:'',
        ID:''
    },
    handlerGobackClick() {
        wx.navigateBack({
          complete: (res) => {},
          delta:1
        })
        
    },
    // 顶部tab切换事件
    toggleCategory(e) {
        console.log(e)
        const that = this;
        that.setData({
        categoryCur: e.detail.index,
        isDoubleClick: e.detail.isDoubleClick,
        });

        if (that.data.isDoubleClick == "1") {
        console.log('添加双击事件')
        }
        if(e.detail.index==1){
            this.setData({
                detailsList:[]
            })
            this.detailsList()
        }
    },
    //播放
    videoPlay(e){
        var playObj={
            activityVideoId:this.data.videoId
        }
        this.video_port(playObj)
    },
    //更换
    uponload(e){
        console.log(e)
        var detailobj = this.data.detailobj
        detailobj.videoUrl = e.currentTarget.dataset.item.videoUrl
        detailobj.picUrl = e.currentTarget.dataset.item.picUrl
        detailobj.title = e.currentTarget.dataset.item.title
        detailobj.numberViewers = e.currentTarget.dataset.item.numberViewers
        this.setData({
            detailobj:detailobj,
            id:e.currentTarget.dataset.item.id,

            // categoryCur:0,
        })
        var uploadObj={
            activityVideoId:e.currentTarget.dataset.item.id
        }
        this.video_port(uploadObj)


        //返回顶部
      wx.pageScrollTo({
        scrollTop: 0,
        duration: 300
      })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        // console.log(options.id)
        this.setData({
            id:options.id
        })  
        this.activity_video()
        
    },
    //活动视频详情
    activity_video(){
        var obj={id:this.data.id}
        // var detailobj=this.data.detailobj
        activityvideo.detail(obj).then(res=>{
            console.log(res)
            // var activityVideoId=this.data.activityVideoId
            this.setData({
                detailobj:res.data.datum,
                // content:res.data.content
                ID:res.data.datum.activityVideoId,
                videoId:res.data.datum.id

            })
            
            var article = res.data.content;
            WxParse.wxParse('article', 'html', article, this, 5);
        }).catch(error=>{
            console.log(error)
        })
    },
    //视频列表
    detailsList(){
        var obj={
            activityVideoId:this.data.ID
        }
        activityvideo.detail_list(obj).then(res=>{
            console.log(res)
            var detailsList=this.data.detailsList
            for(var i=0;i<res.data.datums.length;i++){
                detailsList.push(res.data.datums[i])
            }   
            this.setData({
                detailsList:detailsList
                // detailsList:[]

            })
        }).catch(error=>{
            console.log(error)
        })
    },
    //视频接口
    video_port(obj){
        activityvideo.user_browsing(obj).then(res=>{
            console.log(res)
            this.setData({
                Url:this.data.detailobj.videoUrl
                })
            
        }).catch(error=>{
            console.log(error)
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})